using System;  
using System.Collections; 
using System.Collections.Generic;
/**
*神一样的 coder 永不bug 
*author ${author} 
*${desc}
<#if type=="REQ">${respDesc}*</#if>
*/
public class ${name} <#if type=="REQ">:ProtocolRequestBase<#elseif type=="RESP">:ProtocolResponseBase</#if>{
<#list properties as pro>
	//${pro.desc}//
	public  <#if pro.ref =="list">List<<@CTYPE>${pro.type}</@CTYPE>> ${pro.name}=null<#else><@CTYPE>${pro.type}</@CTYPE> ${pro.name}=<@DEFVAL>${pro.type}</@DEFVAL></#if> ;
</#list>
	//空的构造方法//
	public ${name}()
	{}
	<#if type=="RESP" ||type=="BEAN">
	public override void readData(ByteBuffer data){
	<#list properties as pro>
		<#if pro.isif!=true>
			<#if pro.ref =="bean"> 
				${pro.name}=new ${pro.type}();
				${pro.name}.readData(data);
			<#elseif pro.ref=="list">
				${pro.name}=new List<<@CTYPE>${pro.type}</@CTYPE>>();
				int ${pro.name}Size=data.ReadShort();
				for(int i=0;i<${pro.name}Size;i++){
					<#if pro.type?ends_with("Bean")> 
					${pro.type} tempBean=new ${pro.type}();
					tempBean.readData(data);
					<#else>
					<@CTYPE>${pro.type}</@CTYPE> tempBean=data.Read<@TYPE>${pro.type}</@TYPE>();
					</#if>
					${pro.name}.Add(tempBean);
				}
			<#else>
				${pro.name}=data.Read<@TYPE>${pro.type}</@TYPE>();
				<#list pro.ifs as ifc>
					if(${pro.name} ${ifc.flag} ${ifc.value}){
						<#list ifc.properties as p>
							<#if p.ref =="bean"> 
								${p.name}=new ${p.type}();
								${p.name}.readData(data);
							<#elseif p.ref=="list">
								${p.name}=new List<<@CTYPE>${p.type}</@CTYPE>>();
								int ${p.name}Size=data.ReadShort();
								for(int i=0;i<${p.name}Size;i++){
									<#if p.type?ends_with("Bean")> 
									${p.type} tempBean=new ${p.type}();
									tempBean.readData(data);
									<#else>
									<@CTYPE>${p.type}</@CTYPE> tempBean=data.Read<@TYPE>${p.type}</@TYPE>();
									</#if>
									${p.name}.Add(tempBean);
								}
							<#else>
								${pro.name}=data.Read<@TYPE>${pro.type}</@TYPE>();
							</#if>
						</#list>
					}
				</#list>
			</#if>

		<#else>

		</#if>
	</#list>
	}
	</#if>
	<#if type=="REQ" ||type=="BEAN">
	public  void writeData(ByteBuffer data){
	<#list properties as pro>
	<#if pro.isif!=true>
		<#if pro.ref =="bean"> 
			${pro.name}.writeData(data);
		<#elseif pro.ref=="list">
			data.WriteShort((short)${pro.name}.Count);
			foreach(<@CTYPE>${pro.type}</@CTYPE> tempBean in ${pro.name}){
				<#if pro.type?ends_with("Bean")> 
				tempBean.writeData(data);
				<#else>
				data.Write<@TYPE>${pro.type}</@TYPE>(tempBean);
				</#if>
			}
		<#else>
			data.Write<@TYPE>${pro.type}</@TYPE>(${pro.name});
			<#list pro.ifs as ifc>
					if(${pro.name} ${ifc.flag} ${ifc.value}){
						<#list ifc.properties as p>
							<#if p.ref =="bean"> 
								${p.name}.WriteData(data);
							<#elseif p.ref=="list">
								data.WriteShort((short)${p.name}.Count);
								foreach(<@CTYPE>${p.type}</@CTYPE> tempBean in ${p.name}){
								<#if p.type?ends_with("Bean")> 
									tempBean.writeData(data);
								<#else>
									data.Write<@TYPE>${p.type}</@TYPE>(tempBean);
								</#if>
								}
							<#else>
								data.Write<@TYPE>${p.type}</@TYPE>(${p.name});
							</#if>
						</#list>
					}
				</#list>
		</#if>
	</#if>
	</#list>
	}
	public override void writeData(){
		data=ByteBuffer.Allocate(16);
		<#if type=="REQ">
		data.WriteShort(getMsgCode());
		</#if>
		writeData(data);
	}
	</#if>
	
	<#if type!="BEAN">
	public override short getMsgCode()
	{
		return MessageCode.${conName};
	}
	</#if>
	
	public override string toString(){
		return "${name}["+<#list properties as pro>", ${pro.name}:"+${pro.name}+</#list>"]";

	}
}